package com.atxwq.shop.product.controller;

import com.atxwq.shop.model.entity.product.Category;
import com.atxwq.shop.model.entity.product.Product;
import com.atxwq.shop.model.entity.product.ProductSku;
import com.atxwq.shop.model.vo.common.Result;
import com.atxwq.shop.model.vo.common.ResultCodeEnum;
import com.atxwq.shop.model.vo.h5.IndexVo;
import com.atxwq.shop.product.service.CategoryService;
import com.atxwq.shop.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description TODO
 * @Date 2025/5/18 13:41
 * @Created by 12336
 */

//@CrossOrigin //跨域
@RestController
@RequestMapping("/api/product/index")
public class IndexController {

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private ProductService productService;

    @GetMapping()
    public Result index(){
        //1.所有一级分类
        List<Category> categoryList = categoryService.selectOneCategory();
        //2.获取销量记录，前10条商品
        List<ProductSku> productSkuList = productService.selectSkuProductList();

        IndexVo indexVo = new IndexVo();
        indexVo.setCategoryList(categoryList);
        indexVo.setProductSkuList(productSkuList);

        return Result.build(indexVo, ResultCodeEnum.SUCCESS);
    }


}
